<!--#
layout("/layouts/platform.html"){
#-->
<div id="app" v-cloak>
    <el-row class="header navbar bg-white shadow">
        <div class="btn-group tool-button mt5">
            <span>微信公众号：</span>
            <el-select size="medium" v-trim v-model="pageForm.wxid" placeholder="请选择" @change="change">
                <el-option
                        v-for="item in wxConfigs"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                </el-option>
            </el-select>
        </div>
        <div class="pull-right offscreen-right mt5">
            <el-button size="medium" @click="getTpl">
                <i class="el-icon-download"></i>
                同步模板
            </el-button>
        </div>
    </el-row>
    <el-row class="el-table-container">
        <el-table
                :data="tableData"
                @sort-change='pageOrder'
                size="small"
                header-align="center"
                style="width: 100%"
                :default-sort="{prop: 'opAt', order: 'descending'}"
        >

            <el-table-column label="template_id" header-align="left" prop="template_id"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="模板标题" header-align="left" prop="title"
                             :show-overflow-tooltip="true" width="150">
            </el-table-column>

            <el-table-column label="所属行业" header-align="left" prop="primary_industry"
                             :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    {{scope.row.primary_industry}} - {{scope.row.deputy_industry}}
                </template>
            </el-table-column>

            <el-table-column label="模板示例" header-align="left" prop="example"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="模板内容" header-align="left" prop="content"
                             :show-overflow-tooltip="true">
            </el-table-column>

        </el-table>
    </el-row>
    <el-row class="el-pagination-container">
        <el-pagination
                @size-change="pageSizeChange"
                @current-change="pageNumberChange"
                :current-page="pageForm.pageNumber"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="pageForm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pageForm.totalCount">
        </el-pagination>
    </el-row>

</div>
<script>
    new Vue({
        el: "#app",
        data: function () {
            var wxConfigs = [];
            <!--#for(o in wxList){#-->
            wxConfigs.push({value: "${o.id!}", label: "${o.appname!}"});
            <!--#}#-->
            return {
                wxConfigs: wxConfigs,
                pageForm: {
                    wxid: "<!--#if(!isEmpty(wxConfig)){#-->${wxConfig.id!}<!--#}#-->",
                    searchName: "",
                    searchKeyword: "",
                    pageNumber: 1,
                    pageSize: 10,
                    totalCount: 0,
                    pageOrderName: "opAt",
                    pageOrderBy: "descending"
                },
                tableData: [],
            }
        },
        methods: {
            pageOrder: function (column) {//按字段排序
                this.pageForm.pageOrderName = column.prop;
                this.pageForm.pageOrderBy = column.order;
                this.pageData();
            },
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                var self = this;
                sublime.showLoadingbar();//显示loading
                $.post(base + "/platform/wx/tpl/list/data", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code == 0) {
                        self.tableData = data.data.list;
                        self.pageForm.totalCount = data.data.totalCount;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            formatAt: function (val) {
                if (val > 0)
                    return moment(val * 1000).format("YYYY-MM-DD HH:mm");
                return "";
            },
            handleSelectionChange: function (val) {
                this.selectData = val;
            },
            getTpl:function(){
                var self = this;
                self.$confirm('您确定要同步模板？确定后请稍作等待.. ', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    callback: function (a, b) {
                        if ("confirm" == a) {//确认后再执行
                            $.post(base + "/platform/wx/tpl/list/getDo", {wxid: "<!--#if(!isEmpty(wxConfig)){#-->${wxConfig.id!}<!--#}#-->"}, function (data) {
                                if (data.code == 0) {
                                    self.pageData();
                                } else {
                                    self.$message({
                                        message: data.msg,
                                        type: 'error'
                                    });
                                }
                            }, "json");
                        }
                    }
                });

            },
            change: function (val) {
                window.location.href = "${base}/platform/wx/tpl/list/index/" + val;
            }
        },
        created: function () {
            this.pageData();
        }
    });
</script>
<!--#
}
#-->
